﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kokomo.PeInspector.Reflection.Disassembly;

namespace Kokomo.PeInspector.Reflection
{
	/// <summary>
	/// Represents a code metric within the UI.
	/// </summary>
	/// <remarks>
	/// This class combines a <see cref="CodeMetricDefinition"/>
	/// with the value of the metric.
	/// </remarks>
	public class CodeMetricViewModel
	{
		/// <summary>
		/// Gets the <see cref="CodeMetricDefinition"/> of the metric.
		/// </summary>
		public CodeMetricDefinition Definition { get; private set; }
		/// <summary>
		/// Gets the value of the metric.
		/// </summary>
		public object Value { get; private set; }

		/// <summary>
		/// Initializes a new instance of <see cref="CodeMetricViewModel"/>.
		/// </summary>
		/// <param name="definition">The <see cref="CodeMetricDefinition"/> of the metric.</param>
		/// <param name="value">The value of the metric.</param>
		public CodeMetricViewModel(
			CodeMetricDefinition definition,
			object value
			)
		{
			if (definition == null) throw new ArgumentNullException("definition");

			this.Definition = definition;
			this.Value = value;
		}

		/// <summary>
		/// Gets the label of the metric.
		/// </summary>
		/// <remarks>
		/// Returns the value of <see cref="CodeMetricDefinition.Label"/>.
		/// </remarks>
		public string Label
		{
			get { return this.Definition.Label; }
		}

		/// <summary>
		/// Gets the category of the metric.
		/// </summary>
		/// <remarks>
		/// Returns the value of <see cref="CodeMetricDefinition.Category"/>.
		/// </remarks>
		public string Category
		{
			get { return this.Definition.Category; }
		}

		/// <summary>
		/// Gets the textual representation of <see cref="Value"/>.
		/// </summary>
		public string Text
		{
			get
			{
				return (this.Value == null) ? string.Empty : this.Value.ToString();
			}
		}
	}
}
